//
//  YOGonlineDetailInfo.m
//  YOGProj
//
//  Created by liyun on 14-6-30.
//  Copyright (c) 2014年 liyun. All rights reserved.
//

#import "YOGonlineDetailInfo.h"
#import "HCMacroDefinition.h"
#import "HCDownImageOperation.h"

@interface YOGonlineDetailInfo ()<UIScrollViewDelegate,UIWebViewDelegate>
{
    int heightScr;
    UIView *indicatorView;
    UIView *tipView;
    NSString *cachesDir;
    UIView *largeImageBack;
    NSArray *tempImageArray;
    UILabel *countLabel;
    UIScrollView *showScrollView;
    UIActivityIndicatorView *indicatorSmall;
    IBOutlet UILabel *titleLabel;
    IBOutlet UIImageView *images;
    IBOutlet UILabel *provider;
    IBOutlet UILabel *time;
//    IBOutlet UITextView *content;
    IBOutlet UIWebView *content;
    IBOutlet UIScrollView *detailScroll;
}

@end

@implementation YOGonlineDetailInfo
@synthesize detailInfoDic;

- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
    if (self) {

        if(!detailInfoDic)
            detailInfoDic = [[NSDictionary alloc] init];
    }
    return self;
}

- (void)navigationShowLeft
{
    [self.navigationController popViewControllerAnimated:YES];
}

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    self.view.backgroundColor = [UIColor whiteColor];
    
    if([[UIScreen mainScreen] bounds].size.height != 480.0f)
        heightScr = 568;
    else
        heightScr = 480;
    
    self.title = NSLocalizedString(@"HC青奥动态", @"");
    UIButton *button=[UIButton buttonWithType:UIButtonTypeCustom];
    button.frame=CGRectMake(0, 0, 30, 30);
    [button setBackgroundImage:[UIImage imageWithContentsOfFile:[BUNDLE pathForResource:@"HCback" ofType:@"png"]] forState:UIControlStateNormal];
    [button addTarget:self action:@selector(navigationShowLeft) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem *barItemleft=[[UIBarButtonItem alloc]initWithCustomView:button];
    self.navigationItem.leftBarButtonItem=barItemleft;
    
    UISwipeGestureRecognizer *recognizerRight = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(navigationShowLeft)];
    recognizerRight.direction = UISwipeGestureRecognizerDirectionRight;
    [self.view addGestureRecognizer:recognizerRight];
    
    detailScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, 320, heightScr-64)];
    detailScroll.backgroundColor = [UIColor whiteColor];
    [self.view addSubview:detailScroll];

    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, YES);
    cachesDir = [paths objectAtIndex:0];
    
    titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 300, 48)];
    titleLabel.font = HEIGHT_FONT(16.0f);
    titleLabel.numberOfLines = 2;
    titleLabel.text = detailInfoDic[@"title"];
    [detailScroll addSubview:titleLabel];
    
    provider = [[UILabel alloc] initWithFrame:CGRectMake(10, 55, 195, 21)];
    provider.text = detailInfoDic[@"provider"];
    provider.font = [UIFont systemFontOfSize:12.0];
    provider.textColor = [UIColor darkGrayColor];
    [detailScroll addSubview:provider];

    time = [[UILabel alloc] initWithFrame:CGRectMake(205, 55, 105, 21)];
    time.text = detailInfoDic[@"createDate"];
    time.textAlignment = NSTextAlignmentRight;
    time.font = [UIFont systemFontOfSize:12.0];
    time.textColor = [UIColor darkGrayColor];
    [detailScroll addSubview:time];
    
    images = [[UIImageView alloc] initWithFrame:CGRectMake(10, 80, 300, 150)];
    images.userInteractionEnabled = YES;
    images.image = [UIImage imageWithContentsOfFile:[BUNDLE pathForResource:@"HCdefaultImage" ofType:@"png"]];
    [detailScroll addSubview:images];
    
//    content = [[UITextView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
//    content.text = [NSString stringWithFormat:@"        %@",detailInfoDic[@"content"]];
//    content.editable = NO;
//    content.scrollEnabled = NO;
//    content.textColor = HEX2UIColor(0x898989);
//    content.backgroundColor = [UIColor clearColor];
//    content.font = [UIFont systemFontOfSize:15.0];
    
//    CGSize  size = [detailInfoDic[@"content"] sizeWithFont:[UIFont systemFontOfSize:15]
//                            constrainedToSize:CGSizeMake(300, 6000)
//                                lineBreakMode:NSLineBreakByCharWrapping];
//    int height = size.height +40;
//    
//    NSString *temp = [detailInfoDic[@"content"] stringByReplacingOccurrencesOfString:@"\\r\\n" withString:@"<br/>"];
//    temp = [temp stringByReplacingOccurrencesOfString:@"  " withString:@"&nbsp"];
//    
////    NSArray *tempArr = [detailInfoDic[@"content"] componentsSeparatedByString:@"<br/>"];
////    NSLog(@"%@",tempArr);
//
//    content = [[UIWebView alloc] initWithFrame:CGRectMake(5, images.frame.size.height+85, 310, height)];
//    [content loadHTMLString:temp baseURL:nil];
//    content.scrollView.scrollEnabled = NO;
//    content.delegate = self;
//    [detailScroll addSubview:content];
//    detailScroll.contentSize = CGSizeMake(300, content.frame.origin.y +height);
    
    NSString *displayStr = [NSString stringWithFormat:@"&nbsp&nbsp&nbsp&nbsp%@",detailInfoDic[@"content"]];
    content = [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, 0, 0)];
    [content loadHTMLString:displayStr baseURL:nil];
    content.scrollView.scrollEnabled = NO;
    content.delegate = self;
    //    content.text = detailInfoDic[@"content"];
    NSArray *tempArr = [detailInfoDic[@"content"] componentsSeparatedByString:@"<br/>"];
    NSLog(@"-->%d",tempArr.count);
    CGSize  size = [detailInfoDic[@"content"] sizeWithFont:[UIFont systemFontOfSize:15]
                            constrainedToSize:CGSizeMake(300, 6000)
                                lineBreakMode:NSLineBreakByCharWrapping];
    int height = size.height +40+(tempArr.count+1)*16;
    
    content.frame = CGRectMake(5, images.frame.size.height+85, 310, height);
    [detailScroll addSubview:content];
    detailScroll.contentSize = CGSizeMake(300, content.frame.origin.y +height);


    
    dispatch_queue_t queue=dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
    dispatch_group_t group=dispatch_group_create();
    
    if(!tempImageArray)
        tempImageArray = [[NSArray alloc] initWithArray: detailInfoDic[@"pictures"]];
    
    
    if (tempImageArray.count > 0)
    {
        NSString *urlStr2 = [[tempImageArray objectAtIndex:0]objectForKey:@"url"];

        if(indicatorSmall)
            indicatorSmall = nil;
        indicatorSmall = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        indicatorSmall.frame = CGRectMake(135, 60, 30, 30);
        [images   addSubview:indicatorSmall];
        [indicatorSmall      startAnimating];
        
        NSString *imageName = [NSString stringWithFormat:@"%@",[self curpString:urlStr2]];
        NSString *imageDocu = [cachesDir stringByAppendingPathComponent:imageName];
        
        if([[NSFileManager defaultManager] fileExistsAtPath:imageDocu])
        {
            images.image = [UIImage imageWithContentsOfFile:imageDocu];
            if(indicatorSmall)
                [indicatorSmall removeFromSuperview];
            
            UIImage *avalImage=images.image;
            float bili;
            if(avalImage.size.width>300)
                bili = avalImage.size.width/300;
            else
                bili = 1;
            
            images.frame = CGRectMake(10, 80, 300, avalImage.size.height/bili);
            images.image = avalImage;
            
            int offY = 0;
            if(tempImageArray.count>1)
            {
                NSLog(@"多图--->");
                
                UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(110, images.frame.size.height+85, 100, 15)];
                label.text = NSLocalizedString(@"HC(多图)", @"");
                label.font = NORMAL_FONT(11.0f);
                label.backgroundColor = [UIColor clearColor];
                label.textAlignment = NSTextAlignmentCenter;
                [detailScroll addSubview:label];
                offY = 15;
            }
            content.frame = CGRectMake(5, images.frame.size.height+85+offY, 310, height);
            
            detailScroll.contentSize = CGSizeMake(300, content.frame.origin.y +height);
            
            UITapGestureRecognizer *singleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(largeImageView)];
            [images addGestureRecognizer:singleTap];
        }
        else
        {
            dispatch_group_async(group, queue,^{
                
                NSLog(@"%@",urlStr2);
                NSData *responseData=[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:urlStr2]];
                
                if (responseData !=nil) {
                    UIImage *avalImage=[UIImage imageWithData:responseData];
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        
                        NSString *imageName = [NSString stringWithFormat:@"%@",[self curpString:urlStr2]];
                        NSString *imageDocu = [cachesDir stringByAppendingPathComponent:imageName];
                        [[NSFileManager defaultManager] createFileAtPath:imageDocu contents:responseData attributes:nil];
                        
                        if(indicatorSmall)
                            [indicatorSmall removeFromSuperview];
                        
                        float bili;
                        if(avalImage.size.width>300)
                            bili = avalImage.size.width/300;
                        else
                            bili = 1;
                        
                        images.frame = CGRectMake(10, 80, 300, avalImage.size.height/bili);
                        images.image = avalImage;
                        
                        int offY = 0;
                        if(tempImageArray.count>1)
                        {
                            NSLog(@"多图正在加载");
                            UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(110, images.frame.size.height+85, 100, 15)];
                            label.text = NSLocalizedString(@"HC(多图)", @"");
                            label.font = NORMAL_FONT(11.0f);
                            label.backgroundColor = [UIColor clearColor];
                            label.textAlignment = NSTextAlignmentCenter;
                            [detailScroll addSubview:label];
                            offY = 15;
                        }
                        
                        content.frame = CGRectMake(5, images.frame.size.height+85+offY, 310, height);
                        
                        detailScroll.contentSize = CGSizeMake(300, content.frame.origin.y +height);
                        
                        UITapGestureRecognizer *singleTap=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(largeImageView)];
                        [images addGestureRecognizer:singleTap];
                    });
                }
                else
                {
                    images.image = [UIImage imageWithContentsOfFile:[BUNDLE pathForResource:@"HCdefaultImage2" ofType:@"jpg"]];
                    [[NSNotificationCenter defaultCenter] postNotificationName:@"HCTIP" object:@{@"HCmsg":NSLocalizedString(@"HC图片加载失败", @"")}];
                    //显示失败图片
                }
            });
        }
    }
    else
    {
        [images removeFromSuperview];
        content.frame = CGRectMake(5, 65, 310, height);
        detailScroll.contentSize = CGSizeMake(300, content.frame.origin.y +height);
    }
}

- (BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType
{
    NSLog(@"- (void)loadRequest:(NSURLRequest *)request;-->%@",request.URL);
    [[UIApplication sharedApplication] openURL:request.URL];
    if([request.URL isEqual:[NSURL URLWithString:@"about:blank"]])
        return YES;
    else
        return NO;
}

- (void)webViewDidStartLoad:(UIWebView *)webView
{
    NSLog(@"111");
    //    [content loadHTMLString:detailInfoDic[@"content"] baseURL:nil];
}
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSLog(@"222");
    //    [content loadHTMLString:detailInfoDic[@"content"] baseURL:nil];
}
- (void)webView:(UIWebView *)webView didFailLoadWithError:(NSError *)error
{
    NSLog(@"333");
    //    [content loadHTMLString:detailInfoDic[@"content"] baseURL:nil];
}

- (void)largeImageView
{
    CGSize size=self.view.frame.size;
    
    largeImageBack=[[UIView alloc]initWithFrame:[[UIScreen mainScreen] bounds]];
    largeImageBack.backgroundColor=[UIColor whiteColor];
    
    countLabel = [[UILabel alloc]initWithFrame:CGRectMake(0, 20, size.width, 30)];
    countLabel.text=[NSString stringWithFormat:@"%d/%lu",1,(unsigned long)tempImageArray.count];
    countLabel.textColor=[UIColor blackColor];
    countLabel.textAlignment=NSTextAlignmentCenter;
    countLabel.font=[UIFont systemFontOfSize:21];
    countLabel.backgroundColor=[UIColor clearColor];
    [largeImageBack addSubview:countLabel];
    
    NSLog(@"%f",size.height);
    if(showScrollView)
        showScrollView = nil;
    showScrollView =[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, heightScr)];
    showScrollView.contentSize=CGSizeMake(tempImageArray.count*320, heightScr);
    showScrollView.backgroundColor=[UIColor clearColor];
    showScrollView.showsHorizontalScrollIndicator=NO;
    showScrollView.showsVerticalScrollIndicator=NO;
    showScrollView.bouncesZoom=NO;
    showScrollView.pagingEnabled=YES;
    showScrollView.bounces=NO;
    showScrollView.delegate=self;
    
//    NSURL *url;
//    if (tempImageArray.count >0)
//    {
//        [self loadWaitView];
//        
//        for (int i = 0; i<tempImageArray.count; i++)
//        {
//            url = [NSURL URLWithString:[[tempImageArray objectAtIndex:i]objectForKey:@"url"]];
//            dispatch_group_async(dispatch_group_create(), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{
//                
//                NSData *responseData=[[NSData alloc]initWithContentsOfURL:url];
//                if (responseData !=nil)
//                {
//                    UIImage *avalImage=[UIImage imageWithData:responseData];
//                    
//                    dispatch_async(dispatch_get_main_queue(), ^{
//                        
//                        if(indicatorView)
//                            [indicatorView removeFromSuperview];
//                        
//                        float proportion;
//                        
//                        UIImageView * imagelarge=[[UIImageView alloc]initWithFrame:CGRectMake(i*scrollView.frame.size.width, 0, avalImage.size.width,avalImage.size.height)];
//                        
//                        if(avalImage.size.width >320)
//                        {
//                            proportion = avalImage.size.width/320;
//                            imagelarge.frame = CGRectMake(i*scrollView.frame.size.width, (heightScr-avalImage.size.height/proportion)/2, avalImage.size.width/proportion,avalImage.size.height/proportion);
//                            
//                            if(avalImage.size.height >heightScr)
//                            {
//                                scrollView.contentSize=CGSizeMake(tempImageArray.count*320, imagelarge.frame.size.height);
//                            }
//                        }
//                        else
//                        {
//                            proportion = 320/avalImage.size.width;
//                            imagelarge.frame = CGRectMake(i*scrollView.frame.size.width, (heightScr-avalImage.size.height*proportion)/2, avalImage.size.width*proportion,avalImage.size.height*proportion);
//                            
//                            if(imagelarge.frame.size.height >heightScr)
//                            {
//                                scrollView.contentSize=CGSizeMake(tempImageArray.count*320, imagelarge.frame.size.height);
//                            }
//                        }
//                        imagelarge.image=avalImage;
//                        [imageArray addObject:imagelarge];
//                        imagelarge.userInteractionEnabled=YES;
//                        [scrollView addSubview:imagelarge];
//                    });
//                }else
//                {
////                    [[NSNotificationCenter defaultCenter] postNotificationName:@"HCTIP" object:@{@"HCmsg":NSLocalizedString(@"netError", @"")}];
//                }
//            });
//        }
//        [largeImageBack addSubview:scrollView];
//    }
    
    NSURL *url;
    __block UIImageView *imagelarge = [[UIImageView alloc] init];
    if (tempImageArray.count >0)
    {
        int i = 0;
        
        NSString *urlStr = [[tempImageArray objectAtIndex:i]objectForKey:@"url"];
        
        NSString *imageName = [NSString stringWithFormat:@"%@",[self curpString:urlStr]];
        NSString *imageDocu = [cachesDir stringByAppendingPathComponent:imageName];
        if([[NSFileManager defaultManager] fileExistsAtPath:imageDocu])
        {
            NSLog(@"00%@",imageDocu);
            UIImage *temp = [UIImage imageWithContentsOfFile:imageDocu];
            
            float proportion;
            if(temp.size.width >320)
            {
                proportion = temp.size.width/320;
                imagelarge.frame = CGRectMake(0, (heightScr-temp.size.height/proportion)/2, temp.size.width/proportion,temp.size.height/proportion);
                
                if(temp.size.height >heightScr)
                {
                    showScrollView.contentSize=CGSizeMake(tempImageArray.count*320, imagelarge.frame.size.height);
                }
            }
            else
            {
                proportion = 320/temp.size.width;
                imagelarge.frame = CGRectMake(0, (heightScr-temp.size.height*proportion)/2, temp.size.width*proportion,temp.size.height*proportion);
                
                if(imagelarge.frame.size.height >heightScr)
                {
                    showScrollView.contentSize=CGSizeMake(tempImageArray.count*320, imagelarge.frame.size.height);
                }
            }
            imagelarge.image = temp;
        }
        else
        {
            [self loadWaitView];

            dispatch_group_async(dispatch_group_create(), dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0),^{
                
                NSData *responseData=[[NSData alloc]initWithContentsOfURL:url];
                if (responseData !=nil)
                {
                    UIImage *avalImage=[UIImage imageWithData:responseData];
                    
                    dispatch_async(dispatch_get_main_queue(), ^{
                        
                        if(indicatorView)
                            [indicatorView removeFromSuperview];
                        
                        float proportion;
                        
                        imagelarge=[[UIImageView alloc]initWithFrame:CGRectMake(i*showScrollView.frame.size.width, 0, avalImage.size.width,avalImage.size.height)];
                        
                        if(avalImage.size.width >320)
                        {
                            proportion = avalImage.size.width/320;
                            imagelarge.frame = CGRectMake(i*showScrollView.frame.size.width, (heightScr-avalImage.size.height/proportion)/2, avalImage.size.width/proportion,avalImage.size.height/proportion);
                            
                            if(avalImage.size.height >heightScr)
                            {
                                showScrollView.contentSize=CGSizeMake(tempImageArray.count*320, imagelarge.frame.size.height);
                            }
                        }
                        else
                        {
                            proportion = 320/avalImage.size.width;
                            imagelarge.frame = CGRectMake(i*showScrollView.frame.size.width, (heightScr-avalImage.size.height*proportion)/2, avalImage.size.width*proportion,avalImage.size.height*proportion);
                            
                            if(imagelarge.frame.size.height >heightScr)
                            {
                                showScrollView.contentSize=CGSizeMake(tempImageArray.count*320, imagelarge.frame.size.height);
                            }
                        }
                        imagelarge.image=avalImage;
                        imagelarge.userInteractionEnabled=YES;
                    });
                }else
                {
                    imagelarge.image = [UIImage imageWithContentsOfFile:[BUNDLE pathForResource:@"HCdefaultImage2" ofType:@"png"]];
                }
            });
        }
        [showScrollView addSubview:imagelarge];
        [largeImageBack addSubview:showScrollView];
    }
    [largeImageBack bringSubviewToFront:countLabel];
    
    UITapGestureRecognizer *singleTap1=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(remove)];
    [largeImageBack addGestureRecognizer:singleTap1];
    
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:ANIMATION_TIME];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    self.navigationController.navigationBarHidden=YES;
    [self.view addSubview:largeImageBack];
    [UIView commitAnimations];
}

#pragma mark - scrollView delegate
-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView
{
    int page = (int)scrollView.contentOffset.x/320;
    
    countLabel.text=[NSString stringWithFormat:@"%d/%lu",page+1,(unsigned long)tempImageArray.count];
    
    UIImageView *imagelarge=[[UIImageView alloc]initWithFrame:CGRectMake(page*scrollView.frame.size.width, (heightScr-160)/2, 320,160)];
    [showScrollView addSubview:imagelarge];
    
    NSString *urlStr = [[tempImageArray objectAtIndex:page]objectForKey:@"url"];
    
    NSString *imageName = [NSString stringWithFormat:@"%@",[self curpString:urlStr]];
    NSString *imageDocu = [cachesDir stringByAppendingPathComponent:imageName];
    __block UIImage *temp;
    if([[NSFileManager defaultManager] fileExistsAtPath:imageDocu])
    {
        NSLog(@"%@",imageDocu);
        temp = [UIImage imageWithContentsOfFile:imageDocu];
        
        float proportion;
        if(temp.size.width >320)
        {
            proportion = temp.size.width/320;
            imagelarge.frame = CGRectMake(page*scrollView.frame.size.width, (heightScr-temp.size.height/proportion)/2, temp.size.width/proportion,temp.size.height/proportion);
            
            if(temp.size.height >heightScr)
            {
                scrollView.contentSize=CGSizeMake(tempImageArray.count*320, imagelarge.frame.size.height);
            }
        }
        else
        {
            proportion = 320/temp.size.width;
            imagelarge.frame = CGRectMake(page*scrollView.frame.size.width, (heightScr-temp.size.height*proportion)/2, temp.size.width*proportion,temp.size.height*proportion);
            
            if(imagelarge.frame.size.height >heightScr)
            {
                scrollView.contentSize=CGSizeMake(tempImageArray.count*320, imagelarge.frame.size.height);
            }
        }
        imagelarge.image = temp;
    }
    else
    {
        imagelarge.image = [UIImage imageWithContentsOfFile:[BUNDLE pathForResource:@"HCdefaultImage" ofType:@"png"]];

        if(indicatorSmall)
            indicatorSmall = nil;
        indicatorSmall = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
        indicatorSmall.frame = CGRectMake(145, 66, 30, 30);
        [imagelarge   addSubview:indicatorSmall];
        [indicatorSmall      startAnimating];
        
        dispatch_queue_t downloadQueue = dispatch_queue_create("YOG downloader", NULL);
        dispatch_async(downloadQueue, ^{
            
            NSLog(@"%@",urlStr);
            NSData *responseData=[[NSData alloc]initWithContentsOfURL:[NSURL URLWithString:urlStr]];
            
            dispatch_async(dispatch_get_main_queue(), ^{
                
                if(indicatorSmall)
                    [indicatorSmall removeFromSuperview];
                if(responseData.length != 0)
                {
                    NSString *imageName = [NSString stringWithFormat:@"%@",[self curpString:urlStr]];
                    NSString *imageDocu = [cachesDir stringByAppendingPathComponent:imageName];
                    [[NSFileManager defaultManager] createFileAtPath:imageDocu contents:responseData attributes:nil];
                    
                    temp = [UIImage imageWithData:responseData];
                    float proportion;
                    if(temp.size.width >320)
                    {
                        proportion = temp.size.width/320;
                        imagelarge.frame = CGRectMake(page*scrollView.frame.size.width, (heightScr-temp.size.height/proportion)/2, temp.size.width/proportion,temp.size.height/proportion);
                        
                        if(temp.size.height >heightScr)
                        {
                            scrollView.contentSize=CGSizeMake(tempImageArray.count*320, imagelarge.frame.size.height);
                        }
                    }
                    else
                    {
                        proportion = 320/temp.size.width;
                        imagelarge.frame = CGRectMake(page*scrollView.frame.size.width, (heightScr-temp.size.height*proportion)/2, temp.size.width*proportion,temp.size.height*proportion);
                        
                        if(imagelarge.frame.size.height >heightScr)
                        {
                            scrollView.contentSize=CGSizeMake(tempImageArray.count*320, imagelarge.frame.size.height);
                        }
                    }
                    imagelarge.image = temp;
                }
                else
                    imagelarge.image = [UIImage imageWithContentsOfFile:[BUNDLE pathForResource:@"HCdefaultImage2" ofType:@"png"]];
            });
        });
    }
}

//加载界面
- (void)loadWaitView
{
    if(indicatorView)
        indicatorView = nil;
    indicatorView                      = [[UIView alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    indicatorView.backgroundColor      = [UIColor colorWithRed:1/255.0 green:1/255.0 blue:1/255.0 alpha:0.4f];//LOAD_BACK_COLOR;
    UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleWhiteLarge];
    indicator.frame = CGRectMake(26, 18, 32, 32);
    
    UIImageView *indicatorBackView = [[UIImageView alloc] initWithFrame:CGRectMake(118, (self.view.frame.size.height-68)/2, 84, 68)];
    indicatorBackView.image = [UIImage imageWithContentsOfFile:[BUNDLE pathForResource:@"HCjuhua_back" ofType:@"png"]];
    [indicatorBackView addSubview:indicator];
    
    [indicatorView  addSubview:indicatorBackView];
    [largeImageBack    addSubview:indicatorView];
    [indicator      startAnimating];
}

- (void)remove
{
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:ANIMATION_TIME];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
    self.navigationController.navigationBarHidden = NO;
    if(largeImageBack)
        largeImageBack.alpha = 0;
    [UIView commitAnimations];
    
    [self performSelector:@selector(removeImageBack) withObject:nil afterDelay:ANIMATION_TIME];
}

- (void)removeImageBack
{
    if(largeImageBack)
        [largeImageBack removeFromSuperview];
}

- (NSString *)curpString:(NSString *)str
{
    NSRange range1=[str rangeOfString:@"/" options:NSBackwardsSearch];
    if(range1.location <100)
    {
        str = [str substringFromIndex:range1.location+1];
    }
    
    str = [NSString stringWithFormat:@"X%@",str];
    
    return  str;
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end
